package org.happycomp.radiog.dialog.convert;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Shell;

public class ConvertSelectionDialog extends Dialog {
	
	private boolean deleteWavFile  = true;
	private boolean generateMp3 = true;
	private Button deleteWavCheck;
	private Button mp3Check;
	private Button wavCheck;
	
	public ConvertSelectionDialog(IShellProvider parentShell) {
		super(parentShell);
	}

	public ConvertSelectionDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	protected Control createDialogArea(Composite parent) {

		Composite container = (Composite) super.createDialogArea(parent);
		GridData gdata = new GridData();
		gdata.grabExcessHorizontalSpace = true;
		gdata.horizontalAlignment = SWT.FILL;
		gdata.minimumWidth = 400;
		
		wavCheck = new Button(container, SWT.CHECK);
		wavCheck.setText("Generuj wav");
		wavCheck.setSelection(true);
		wavCheck.setEnabled(false);
		wavCheck.setLayoutData(gdata);
		
		gdata = new GridData();
		gdata.grabExcessHorizontalSpace = true;
		gdata.horizontalAlignment = SWT.FILL;
		gdata.minimumWidth = 400;
		
		mp3Check = new Button(container, SWT.CHECK);
		mp3Check.setText("Generuj mp3");
		mp3Check.setLayoutData(gdata);
		mp3Check.setSelection(true);
		mp3Check.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				mp3FlagChanged(mp3Check.getSelection());
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
//				mp3FlagChanged(false);
			}
		});
		
		gdata = new GridData();
		gdata.grabExcessHorizontalSpace = true;
		gdata.horizontalAlignment = SWT.FILL;
		gdata.minimumWidth = 400;

		deleteWavCheck = new Button(container, SWT.CHECK);
		deleteWavCheck.setText("Smaz wav soubor");
		deleteWavCheck.setLayoutData(gdata);
		deleteWavCheck.setSelection(true);
		deleteWavCheck.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				deleteWavFlagChanged(deleteWavCheck.getSelection());
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
//				deleteWavFlagChanged(false);
			}
			
		});
		
		return container;

	}
	
	
	
	protected void deleteWavFlagChanged(boolean b) {
		this.deleteWavFile = b;		
	}

	protected void mp3FlagChanged(boolean b) {
		this.generateMp3 = b;
		if (this.generateMp3) {
			this.deleteWavCheck.setEnabled(true);
		} else {
			this.deleteWavCheck.setSelection(false);
			this.deleteWavCheck.setEnabled(false);
		}
	}

	public boolean getDeleteWavFileFlag() {
		return deleteWavFile;
	}
	
	public boolean getGenerateMp3Flag() {
		return generateMp3;
	}
	
}
